C#

推荐列表 站点导航

当前位置:首页 > 脚本编程 > C# >

C#_C#中的文件路径获取函数和文件名字获取函数小结,1. 获取绝对文件路径复制代

来源:网络整理  作者:  发布时间:2020-12-19 21:39
C#中的文件路径获取函数和文件名字获取函数小结,1. 获取绝对文件路径复制代码 代码如下:System.IO.Path.GetFullPath(strin...

1. 获取绝对文件路径

复制代码 代码如下:


System.IO.Path.GetFullPath(string path)

string fileName = "myfile.ext";
string path1 = @"mydir";
string path2 = @"\mydir";
string fullPath;

fullPath = Path.GetFullPath(path1);
fullPath = Path.GetFullPath(fileName);
fullPath = Path.GetFullPath(path2);


2. 获取文件名字(得到指定路径内的文件名,不包括扩展名)

复制代码 代码如下:


System.IO.Path.GetFileNameWithoutExtension(string path)
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;
result = Path.GetFileNameWithoutExtension(fileName);
result = Path.GetFileName(path);


3.获得包含 path 目录信息的string 或者为空引用

复制代码 代码如下:


System.IO.Path.GetDirectoryName(string path)

string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string rootPath = @"C:\";
string directoryName;
   
directoryName = Path.GetDirectoryName(fileName);
directoryName = Path.GetDirectoryName(path);
directoryName = Path.GetDirectoryName(rootPath);


4.合并两个路径字符串。

复制代码 代码如下:


System.IO.Path.Combine(String path1, String path2)

相关热词: C#

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/c/5829.shtml

最新文章
热门文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

C#_C#中的文件路径获取函数和文件名字获取函数小结,1. 获取绝对文件路径复制代

2020-12-19 编辑:

1. 获取绝对文件路径

复制代码 代码如下:


System.IO.Path.GetFullPath(string path)

string fileName = "myfile.ext";
string path1 = @"mydir";
string path2 = @"\mydir";
string fullPath;

fullPath = Path.GetFullPath(path1);
fullPath = Path.GetFullPath(fileName);
fullPath = Path.GetFullPath(path2);


2. 获取文件名字(得到指定路径内的文件名,不包括扩展名)

复制代码 代码如下:


System.IO.Path.GetFileNameWithoutExtension(string path)
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;
result = Path.GetFileNameWithoutExtension(fileName);
result = Path.GetFileName(path);


3.获得包含 path 目录信息的string 或者为空引用

复制代码 代码如下:


System.IO.Path.GetDirectoryName(string path)

string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string rootPath = @"C:\";
string directoryName;
   
directoryName = Path.GetDirectoryName(fileName);
directoryName = Path.GetDirectoryName(path);
directoryName = Path.GetDirectoryName(rootPath);


4.合并两个路径字符串。

复制代码 代码如下:


System.IO.Path.Combine(String path1, String path2)

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/c/5829.shtml

相关文章

风云图片

推荐阅读

返回C#频道首页